//
// Created by liuyang on 15-9-12.
//

#ifndef GRAPH_QUEUE_H_H
#define GRAPH_QUEUE_H_H
#define QUEUE_LENGTH 100
#include <exception>


template <class E>
class Queue{
private:
    E arr[QUEUE_LENGTH];
    int startCount; // The first site whose data is valid
    int endCount; //The first site whose data is NULL
    //if(startCount == endCount) means No data in Queue
    //if(startCount == endCount+1) means Queue is full
public:
    //Constructor
    Queue():startCount(0),endCount(0){}

    int getCount(){
        if(endCount >= startCount) return endCount-startCount;
        return endCount + QUEUE_LENGTH - startCount;
    }

    int isEmpty(){
        if(startCount == endCount) return true;
        else return false;
    }

    void push_back(E a){
        if(startCount == (endCount+1)%QUEUE_LENGTH)
            return;
        arr[endCount] = a;
        endCount = (endCount+1)%QUEUE_LENGTH;
    }

    E pop_front(){
        if(startCount == endCount){
            std::exception e;
            throw e;
        }
        E temp = arr[startCount];
        startCount++;
        startCount = startCount%QUEUE_LENGTH;
        return temp;
    }
};

#endif //GRAPH_QUEUE_H_H
